package problem1;

import java.util.ArrayList;
import java.util.Collection;

public class Main {

	public static void main(String[] args) {
		testWork();
	}
	
	public static <T> void fromArrayToCollection(T[] a, Collection<T> c) {
		if (a!=null && c!=null) {
		for (T elem:a) {
			c.add(elem);
		}
		}
	}
	
	public static void testWork() {
		String[] ss = {"Hello","Generics","let","test","this","interesting","thing"};
		/*
		 *   Compilation error!
		 *   Collection<Integer> cs=new ArrayList<Integer>(); 
		 *   fromArrayToCollection(ss,cs);
		 */
		
		Collection<String> cs=new ArrayList<String>(); 
		fromArrayToCollection(ss,cs);
		System.out.println(cs);
		
		Integer[] ia = {1,5,10,11,18,54};
		Collection<Integer> ci = new ArrayList<Integer>();
		fromArrayToCollection(ia,ci);
		System.out.println(ci);
		
		Object[] oa = null;
		Collection<Object> co = null;
		fromArrayToCollection(oa,co);
	}
}
